<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            quick-search-placeholder="根据分类名称模糊查询" />
        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table />
        <!-- 审核 -->
        <audit />
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted, provide } from 'vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import audit from './audit.vue'
import { useI18n } from 'vue-i18n'
import { baTableApi } from '/@/api/common'
import baTableClass from '/@/utils/baTable'
import { invoiveInfo } from '/@/api/backend/invoice/index'
defineOptions({
    // eslint-disable-next-line vue/multi-word-component-names
    name: 'list/index',
})
let optButtons: OptButton[] = [
    {
        render: 'tipButton',
        name: 'info',
        title: '开票',
        text: '',
        type: 'primary',
        icon: 'fa fa-legal',
        class: 'table-row-info',
        disabledTip: false,
        click: (row: TableRow) => {
            auditButtonClick(row[baTable.table.pk!])
        },
    }
]
const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi('/admin/v1/invoice/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
        
            { label: '用户', prop: 'user.username', align: 'center' },
            { label: '开票金额', prop: 'price', align: 'center' },
            { label: '抬头', prop: 'invoice_header', align: 'center', operator: 'LIKE', operatorPlaceholder: '请输入抬头',showOverflowTooltip: true, },
            { label: '纳税识别号', prop: 'invoice_tax_no', align: 'center', operator: 'LIKE', operatorPlaceholder: '请输入纳税识别号' ,showOverflowTooltip: true,},
            { label: '发票类型', prop: 'invoice_type_text', align: 'center' },
            { label: '抬头类型', prop: 'invoice_header_type_text', align: 'center' },
            { label: '发票内容', prop: 'invoice_service_text', align: 'center',showOverflowTooltip: true, },
            { label: '发送邮箱', prop: 'email', align: 'center',   showOverflowTooltip: true, },
            { label: '订单号', prop: 'order.order_no', align: 'center',showOverflowTooltip: true, },
            { label: '订单内容', prop: 'order.remark', align: 'center',   showOverflowTooltip: true, },
            {
              label: t('State'),
              prop: 'invoice_status',
              align: 'center',
              render: 'tag',
              custom: { '0': 'danger', '1': 'success'  },
              replaceValue: { '0': '申请中', '1':'已开票' },
            },
            {
                label:'申请时间',
                prop: 'create_time',
                align: 'center',
                render: 'datetime',
                sortable: 'custom',
                operator: false,showOverflowTooltip: true,
            },
            { label: t('Operate'), align: 'center', width: '130', render: 'buttons', operator: false, buttons: optButtons }
        ],
        dblClickNotEditColumn: ['all']
    },
    {
        defaultItems: {
            status:1,
        },
    }
)
//审核
const auditButtonClick = (id: string) => {
    console.log(id)
    baTable.form.extend!['audit'] = {}
    baTable.form.operate = 'Audit'
    baTable.form.loading = true
    invoiveInfo(id).then((res: any) => {
        baTable.form.extend!['audit'] = res.data.list
        baTable.form.loading = false
    })
}

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.dragSort()
    })
})
</script>

<style scoped lang="scss"></style>
